﻿using Quartz;
using Quartz.Impl;

namespace HDSmartCommunity
{
    public class ServiceWorkTask
    {
        public static async void Work()
        {
            try
            {
                //调度器工厂
                ISchedulerFactory factory = new StdSchedulerFactory();
                //调度器
                IScheduler scheduler = await factory.GetScheduler();

                //启动
                await scheduler.Start();
                /*-------------计划任务代码实现------------------*/
                //创建任务
                IJobDetail job = JobBuilder.Create<TimeJob>().Build();
                //创建触发器
                //string time = "0 11 13 * * ? *";
                //ITrigger trigger = TriggerBuilder.Create().WithIdentity("TimeTrigger", "TimeGroup").WithSchedule(CronScheduleBuilder.CronSchedule(time).WithMisfireHandlingInstructionDoNothing()).Build();
                ITrigger trigger = TriggerBuilder.Create().WithIdentity("TimeTrigger", "TimeGroup").WithSimpleSchedule(t => t.WithIntervalInHours(24).RepeatForever()).Build();
                //添加任务及触发器至调度器中
                await scheduler.ScheduleJob(job, trigger);
                /*-------------计划任务代码实现------------------*/
            }
            catch
            {

            }
        }

    }
}
